package com.xuan.friend.controller.contest;

import com.xuan.common.core.controller.BaseController;
import com.xuan.common.core.domain.R;
import com.xuan.common.core.domain.TableDataInfo;
import com.xuan.common.core.exception.BusinessException;
import com.xuan.friend.domain.contest.dto.ContestQueryDTO;
import com.xuan.friend.domain.contest.dto.ContestRankDTO;
import com.xuan.friend.service.contest.ContestService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/contest")
public class ContestController extends BaseController {

    @Resource
    private ContestService contestService;


    @GetMapping("/semiLogin/list")
    public TableDataInfo listContest(ContestQueryDTO contestQueryDTO) {
        if (contestQueryDTO == null) {
            throw new BusinessException("参数为空");
        }
        return TableDataInfo.success(contestService.listContest(contestQueryDTO));
    }

    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisListContest(ContestQueryDTO contestQueryDTO) {
        if (contestQueryDTO == null) {
            throw new BusinessException("参数为空");
        }
        return contestService.redisListContest(contestQueryDTO);
    }

    @GetMapping("/semiLogin/rank/list")
    public TableDataInfo listRank(ContestRankDTO contestRankDTO) {
        if (contestRankDTO == null || contestRankDTO.getContestId() == null) {
            throw new BusinessException("参数为空");
        }
        return contestService.listRank(contestRankDTO);
    }


    @GetMapping("/getFirstQuestion")
    public R<String> getFirstQuestionId(Long contestId) {
        if (contestId == null) {
            throw new BusinessException("参数为空");
        }
        return R.ok(contestService.getFirstQuestionId(contestId));
    }

    @GetMapping("/prevQuestion")
    public R<String> prevQuestion(Long questionId, Long contestId) {
        if (questionId == null || contestId == null) {
            throw new BusinessException("参数为空");
        }
        return R.ok(contestService.prevQuestion(questionId, contestId));
    }

    @GetMapping("/nextQuestion")
    public R<String> nextQuestion(Long questionId, Long contestId) {
        if (questionId == null || contestId == null) {
            throw new BusinessException("参数为空");
        }
        return R.ok(contestService.nextQuestion(questionId, contestId));
    }

}
